package com.yamanyar.weebill.view;

import java.io.Serializable;

import javax.faces.application.FacesMessage;
import javax.faces.context.FacesContext;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import com.yamanyar.weebill.domain.ActionPathElement;
import com.yamanyar.weebill.service.ActionPathElementService;

/**
 * Creates an ActionPathElement. Created in Jun 28, 2008.
 * 
 * @author Kaan Yamanyar
 */
@Component("createActionPathElement")
@Scope("request")
public class CreateActionPathElement implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = 6785907946599065081L;

	private ActionPathElementService actionPathElementService;

	private ActionPathElement actionPathElement = new ActionPathElement();

	@Autowired
	public CreateActionPathElement(
			ActionPathElementService actionPathElementService) {
		this.actionPathElementService = actionPathElementService;
	}

	public ActionPathElement getActionPathElement() {
		return actionPathElement;
	}

	public void setActionPathElement(ActionPathElement actionPathElement) {
		this.actionPathElement = actionPathElement;
	}

	public String save() {
		actionPathElementService.createNew(actionPathElement);
		FacesMessage facesMessage = new FacesMessage(
				FacesMessage.SEVERITY_INFO,
				"ActionPathElement is saved successfully", "OK");
		FacesContext.getCurrentInstance().addMessage(null, facesMessage);
		actionPathElement = new ActionPathElement();
		return null;
	}
}
